﻿namespace IPMS.BLL
{
    using IPMS.DAL;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;

    public class Project
    {
        private string _Agent;
        private string _AgentContactEmail3;
        private string _AgentContactEmail4;
        private string _AgentContactFax3;
        private string _AgentContactFax4;
        private string _AgentContactPerson3;
        private string _AgentContactPerson4;
        private string _AgentContactPhone3;
        private string _AgentContactPhone4;
        private string _AltContactEmailAddress;
        private string _AltContactFax;
        private string _AltContactPerson;
        private string _AltContactPersonTitle;
        private string _AltContactPhone;
        private string _Applicant;
        private string _ApplicantNumber;
        private string _ClientContactEmail3;
        private string _ClientContactEmail4;
        private string _ClientContactFax3;
        private string _ClientContactFax4;
        private string _ClientContactPerson3;
        private string _ClientContactPerson4;
        private string _ClientContactPhone3;
        private string _ClientContactPhone4;
        private string _ClientName;
        private string _Country;
        private DateTime _FilingDate;
        private bool _FirstFilingYN;
        private DateTime _GrantDate;
        private string _Inventor;
        private string _PatentNumber;
        private bool _PCTYN;
        private bool _Priority;
        private string _PriorityCountry;
        private DateTime _PriorityDate;
        private string _ProjectClass;
        private string _ProjectCode;
        private string _ProjectGroupId;
        private string _PublicationNumber;
        private string _Remarks;
        private string _Status;
        private string _Title;
        private string _Type;

        public int CheckProjectFirstFiling(string ProjectGroupID, string ProjectCode, out string TargetProjectCode, out byte Enabled, out string ProjectClass, out DateTime FirstFilingDate, out DateTime PriorityDate, out string PCTCountry, out DateTime PCTPriorityDate, out byte Expired)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            TargetProjectCode = "";
            Enabled = 0;
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectGroupID);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectCode);
            DAL.AddParamToSQLCmd(sqlCmd, "@TargetProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Enabled", SqlDbType.TinyInt, 1, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectClass", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@FirstFilingDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PriorityDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PCTCountry", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PCTPriorityDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Expired", SqlDbType.TinyInt, 1, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "CheckProjectFirstFilingSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            TargetProjectCode = Convert.ToString(sqlCmd.Parameters["@TargetProjectCode"].Value);
            Enabled = Convert.ToByte(sqlCmd.Parameters["@Enabled"].Value);
            ProjectClass = Convert.ToString(sqlCmd.Parameters["@ProjectClass"].Value);
            FirstFilingDate = Convert.ToDateTime(sqlCmd.Parameters["@FirstFilingDate"].Value);
            PriorityDate = Convert.ToDateTime(sqlCmd.Parameters["@PriorityDate"].Value);
            PCTCountry = Convert.ToString(sqlCmd.Parameters["@PCTCountry"].Value);
            PCTPriorityDate = Convert.ToDateTime(sqlCmd.Parameters["@PCTPriorityDate"].Value);
            Expired = Convert.ToByte(sqlCmd.Parameters["@Expired"].Value);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int CheckProjectStatus(string ProjectGroupID, string ProjectCode, out string Status)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            Status = string.Empty;
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectGroupID);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectCode);
            DAL.AddParamToSQLCmd(sqlCmd, "@Status", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "CheckProjectStatusSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            Status = Convert.ToString(sqlCmd.Parameters["@Status"].Value);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int GetLicenseCount()
        {
            int Count = 0;
            try
            {
                try
                {
                    Count = Convert.ToInt16(Convert.ToChar(ConfigurationManager.AppSettings["LicenseKey"].ToString().Substring(15, 1))) - 0x40;
                }
                catch (Exception)
                {
                    Count = 0;
                }
            }
            finally
            {
            }
            return Count;
        }

        public int GetProjectDefault(string ProjectGroupID, out string ProjectClass)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            ProjectClass = string.Empty;
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectGroupID);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectClass", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetProjectDefaultValuesSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            ProjectClass = Convert.ToString(sqlCmd.Parameters["@ProjectClass"].Value);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int GetProjectHeadingSetStatusSp(string ProjectCode, string UserId, out string HeadingSet, out string HeadingSetStatus, out bool ResponsiblePersonYN)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            //Guid gid = new Guid(UserId);
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectCode);
            DAL.AddParamToSQLCmd(sqlCmd, "@UserId", SqlDbType.NVarChar, 0, ParameterDirection.Input, UserId);
            DAL.AddParamToSQLCmd(sqlCmd, "@HeadingSet", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@HeadingSetStatus", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ResponsiblePersonYN", SqlDbType.TinyInt, 0, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetProjectHeadingSetStatusSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            HeadingSet = Convert.ToString(sqlCmd.Parameters["@HeadingSet"].Value);
            HeadingSetStatus = Convert.ToString(sqlCmd.Parameters["@HeadingSetStatus"].Value);
            if (Convert.ToInt16(sqlCmd.Parameters["@ResponsiblePersonYN"].Value) == 1)
            {
                ResponsiblePersonYN = true;
            }
            else
            {
                ResponsiblePersonYN = false;
            }
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int GetProjectInfo(string projectgroupid, string projectcode, string type)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, projectgroupid);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Input, projectcode);
            DAL.AddParamToSQLCmd(sqlCmd, "@Type", SqlDbType.NVarChar, 30, ParameterDirection.Input, type);
            DAL.AddParamToSQLCmd(sqlCmd, "@Status", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Country", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Agent", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Title", SqlDbType.NVarChar, 60, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Applicant", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Inventor", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ApplicationNo", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PatentNumber", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PriorityDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PriorityCountry", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientName", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@FilingDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@GrantDate", SqlDbType.DateTime, 8, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@FirstFilingYN", SqlDbType.Bit, 1, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PCTYN", SqlDbType.Bit, 1, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@PublicationNumber", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Remark", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AltContactPerson", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AltContactPersonTitle", SqlDbType.NVarChar, 60, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AltContactFax", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AltContactPhone", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AltContactEmailAddress", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectClass", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Priority", SqlDbType.Bit, 1, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactPerson3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactFax3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactPhone3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactEmailAddress3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactPerson4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactFax4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactPhone4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@AgentContactEmailAddress4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactPerson3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactFax3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactPhone3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactEmailAddress3", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactPerson4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactFax4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactPhone4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ClientContactEmailAddress4", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "RetrieveProjectSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            this._Status = Convert.ToString(sqlCmd.Parameters["@Status"].Value);
            this._Country = Convert.ToString(sqlCmd.Parameters["@Country"].Value);
            this._Agent = Convert.ToString(sqlCmd.Parameters["@Agent"].Value);
            this._Title = Convert.ToString(sqlCmd.Parameters["@Title"].Value);
            this._Applicant = Convert.ToString(sqlCmd.Parameters["@Applicant"].Value);
            this._Inventor = Convert.ToString(sqlCmd.Parameters["@Inventor"].Value);
            this._ApplicantNumber = Convert.ToString(sqlCmd.Parameters["@ApplicationNo"].Value);
            this._PatentNumber = Convert.ToString(sqlCmd.Parameters["@PatentNumber"].Value);
            this._PriorityDate = Convert.ToDateTime(sqlCmd.Parameters["@PriorityDate"].Value);
            this._PriorityCountry = Convert.ToString(sqlCmd.Parameters["@PriorityCountry"].Value);
            this._ClientName = Convert.ToString(sqlCmd.Parameters["@ClientName"].Value);
            this._FilingDate = Convert.ToDateTime(sqlCmd.Parameters["@FilingDate"].Value);
            this._GrantDate = Convert.ToDateTime(sqlCmd.Parameters["@GrantDate"].Value);
            this._FirstFilingYN = Convert.ToBoolean(sqlCmd.Parameters["@FirstFilingYN"].Value);
            this._PCTYN = Convert.ToBoolean(sqlCmd.Parameters["@PCTYN"].Value);
            this._PublicationNumber = Convert.ToString(sqlCmd.Parameters["@PublicationNumber"].Value);
            this._Remarks = Convert.ToString(sqlCmd.Parameters["@Remark"].Value);
            this._AltContactPerson = Convert.ToString(sqlCmd.Parameters["@AltContactPerson"].Value);
            this._AltContactPersonTitle = Convert.ToString(sqlCmd.Parameters["@AltContactPersonTitle"].Value);
            this._AltContactFax = Convert.ToString(sqlCmd.Parameters["@AltContactFax"].Value);
            this._AltContactPhone = Convert.ToString(sqlCmd.Parameters["@AltContactPhone"].Value);
            this._AltContactEmailAddress = Convert.ToString(sqlCmd.Parameters["@AltContactEmailAddress"].Value);
            this._ProjectClass = Convert.ToString(sqlCmd.Parameters["@ProjectClass"].Value);
            this._Priority = Convert.ToBoolean(sqlCmd.Parameters["@Priority"].Value);
            this._AgentContactPerson3 = Convert.ToString(sqlCmd.Parameters["@AgentContactPerson3"].Value);
            this._AgentContactFax3 = Convert.ToString(sqlCmd.Parameters["@AgentContactFax3"].Value);
            this._AgentContactPhone3 = Convert.ToString(sqlCmd.Parameters["@AgentContactPhone3"].Value);
            this._AgentContactEmail3 = Convert.ToString(sqlCmd.Parameters["@AgentContactEmailAddress3"].Value);
            this._AgentContactPerson4 = Convert.ToString(sqlCmd.Parameters["@AgentContactPerson4"].Value);
            this._AgentContactFax4 = Convert.ToString(sqlCmd.Parameters["@AgentContactFax4"].Value);
            this._AgentContactPhone4 = Convert.ToString(sqlCmd.Parameters["@AgentContactPhone4"].Value);
            this._AgentContactEmail4 = Convert.ToString(sqlCmd.Parameters["@AgentContactEmailAddress4"].Value);
            this._ClientContactPerson3 = Convert.ToString(sqlCmd.Parameters["@ClientContactPerson3"].Value);
            this._ClientContactFax3 = Convert.ToString(sqlCmd.Parameters["@ClientContactFax3"].Value);
            this._ClientContactPhone3 = Convert.ToString(sqlCmd.Parameters["@ClientContactPhone3"].Value);
            this._ClientContactEmail3 = Convert.ToString(sqlCmd.Parameters["@ClientContactEmailAddress3"].Value);
            this._ClientContactPerson4 = Convert.ToString(sqlCmd.Parameters["@ClientContactPerson4"].Value);
            this._ClientContactFax4 = Convert.ToString(sqlCmd.Parameters["@ClientContactFax4"].Value);
            this._ClientContactPhone4 = Convert.ToString(sqlCmd.Parameters["@ClientContactPhone4"].Value);
            this._ClientContactEmail4 = Convert.ToString(sqlCmd.Parameters["@ClientContactEmailAddress4"].Value);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int GetProjectStatus(string projectCode, bool superUser, string ownerGroupId)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Input, projectCode);
            DAL.AddParamToSQLCmd(sqlCmd, "@SuperUser", SqlDbType.Bit, 1, ParameterDirection.Input, superUser ? 1 : 0);
            DAL.AddParamToSQLCmd(sqlCmd, "@OwnerGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, ownerGroupId);
            DAL.AddParamToSQLCmd(sqlCmd, "@Status", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetStatusSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
            this._Status = (string) sqlCmd.Parameters["@Status"].Value;
            return resultValue;
        }

        public int GetProjectType(string ProjectCode, out string ProjectType)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectCode);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectType", SqlDbType.NVarChar, 30, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetProjectTypeSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            ProjectType = Convert.ToString(sqlCmd.Parameters["@ProjectType"].Value);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int GetUserProjectCount(string User)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@User", SqlDbType.NVarChar, 30, ParameterDirection.Input, User);
            DAL.AddParamToSQLCmd(sqlCmd, "@Count", SqlDbType.Int, 0, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetProjectCountSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            return (int) sqlCmd.Parameters["@Count"].Value;
        }

        public int PriorityDateExpired(string ProjectGroupID, out byte Expired)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            Expired = 0;
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectGroupID", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectGroupID);
            DAL.AddParamToSQLCmd(sqlCmd, "@Expired", SqlDbType.TinyInt, 1, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "PriorityDateIsExpired");
            DAL.ExecuteScalarCmd(sqlCmd);
            Expired = Convert.ToByte(sqlCmd.Parameters["@Expired"].Value);
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public int UpdateProjectHeadingSetStatusSp(string ProjectCode, string HeadingSetStatus, out string outHeadingSetStatus)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 30, ParameterDirection.Input, ProjectCode);
            DAL.AddParamToSQLCmd(sqlCmd, "@HeadingSetStatus", SqlDbType.NVarChar, 30, ParameterDirection.InputOutput, HeadingSetStatus);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "UpdateProjectHeadingSetStatusSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            outHeadingSetStatus = sqlCmd.Parameters["@HeadingSetStatus"].Value.ToString();
            return Convert.ToInt16(sqlCmd.Parameters["@ReturnValue"].Value);
        }

        public bool Update(bool IsDelete, string UpdateBy, string UpdateIP, string ProjectCode)
        {
            bool isSuccess = false;
            try
            {
                SqlCommand sqlCommand = new SqlCommand();
                DataAccessLayer DAL = new DataAccessLayer();

                string sqlString = "UPDATE [Project] SET IsDelete = @IsDelete,UpdateBy = @UpdateBy,UpdateDate = GETDATE(), UpdateIP = @UpdateIP WHERE (([ProjectCode] = @Original_ProjectCode))";

                DAL.SetCommandType(sqlCommand, CommandType.Text, sqlString);
                DAL.AddParamToSQLCmd(sqlCommand, "@IsDelete", SqlDbType.Bit, 1, ParameterDirection.Input, IsDelete);
                DAL.AddParamToSQLCmd(sqlCommand, "@UpdateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, UpdateBy);
                DAL.AddParamToSQLCmd(sqlCommand, "@UpdateIP", SqlDbType.NVarChar, 50, ParameterDirection.Input, UpdateIP);
                DAL.AddParamToSQLCmd(sqlCommand, "@Original_ProjectCode", SqlDbType.NVarChar, 60, ParameterDirection.Input, ProjectCode);
                DAL.ExecuteScalarCmd(sqlCommand);

                isSuccess = true;
            }
            catch { }

            return isSuccess;
        }

        public bool Delete(string ProjectCode)
        {
            bool isSuccess = false;
            try
            {
                SqlCommand sqlCommand = new SqlCommand();
                DataAccessLayer DAL = new DataAccessLayer();

                string sqlString = "Delete From [Project] WHERE (([ProjectCode] = @Original_ProjectCode))";

                DAL.SetCommandType(sqlCommand, CommandType.Text, sqlString);
                DAL.AddParamToSQLCmd(sqlCommand, "@Original_ProjectCode", SqlDbType.NVarChar, 60, ParameterDirection.Input, ProjectCode);
                DAL.ExecuteScalarCmd(sqlCommand);

                isSuccess = true;
            }
            catch { }

            return isSuccess;
        }

        public string Agent
        {
            get
            {
                return this._Agent;
            }
        }

        public string AgentContactEmail3
        {
            get
            {
                return this._AgentContactEmail3;
            }
        }

        public string AgentContactEmail4
        {
            get
            {
                return this._AgentContactEmail4;
            }
        }

        public string AgentContactFax3
        {
            get
            {
                return this._AgentContactFax3;
            }
        }

        public string AgentContactFax4
        {
            get
            {
                return this._AgentContactFax4;
            }
        }

        public string AgentContactPerson3
        {
            get
            {
                return this._AgentContactPerson3;
            }
        }

        public string AgentContactPerson4
        {
            get
            {
                return this._AgentContactPerson4;
            }
        }

        public string AgentContactPhone3
        {
            get
            {
                return this._AgentContactPhone3;
            }
        }

        public string AgentContactPhone4
        {
            get
            {
                return this._AgentContactPhone4;
            }
        }

        public string AltContactEmailAddress
        {
            get
            {
                return this._AltContactEmailAddress;
            }
        }

        public string AltContactFax
        {
            get
            {
                return this._AltContactFax;
            }
        }

        public string AltContactPerson
        {
            get
            {
                return this._AltContactPerson;
            }
        }

        public string AltContactPersonTitle
        {
            get
            {
                return this._AltContactPersonTitle;
            }
        }

        public string AltContactPhone
        {
            get
            {
                return this._AltContactPhone;
            }
        }

        public string Applicant
        {
            get
            {
                return this._Applicant;
            }
        }

        public string ApplicantNumber
        {
            get
            {
                return this._ApplicantNumber;
            }
        }

        public string ClientContactEmail3
        {
            get
            {
                return this._ClientContactEmail3;
            }
        }

        public string ClientContactEmail4
        {
            get
            {
                return this._ClientContactEmail4;
            }
        }

        public string ClientContactFax3
        {
            get
            {
                return this._ClientContactFax3;
            }
        }

        public string ClientContactFax4
        {
            get
            {
                return this._ClientContactFax4;
            }
        }

        public string ClientContactPerson3
        {
            get
            {
                return this._ClientContactPerson3;
            }
        }

        public string ClientContactPerson4
        {
            get
            {
                return this._ClientContactPerson4;
            }
        }

        public string ClientContactPhone3
        {
            get
            {
                return this._ClientContactPhone3;
            }
        }

        public string ClientContactPhone4
        {
            get
            {
                return this._ClientContactPhone4;
            }
        }

        public string ClientName
        {
            get
            {
                return this._ClientName;
            }
        }

        public string Country
        {
            get
            {
                return this._Country;
            }
        }

        public DateTime FilingDate
        {
            get
            {
                return this._FilingDate;
            }
        }

        public bool FirstFilingYN
        {
            get
            {
                return this._FirstFilingYN;
            }
        }

        public DateTime GrantDate
        {
            get
            {
                return this._GrantDate;
            }
        }

        public string Inventor
        {
            get
            {
                return this._Inventor;
            }
        }

        public string PatentNumber
        {
            get
            {
                return this._PatentNumber;
            }
        }

        public bool PCTYN
        {
            get
            {
                return this._PCTYN;
            }
        }

        public bool Priority
        {
            get
            {
                return this._Priority;
            }
        }

        public string PriorityCountry
        {
            get
            {
                return this._PriorityCountry;
            }
        }

        public DateTime PriorityDate
        {
            get
            {
                return this._PriorityDate;
            }
        }

        public string ProjectClass
        {
            get
            {
                return this._ProjectClass;
            }
        }

        public string ProjectCode
        {
            get
            {
                return this._ProjectCode;
            }
        }

        public string ProjectGroupId
        {
            get
            {
                return this._ProjectGroupId;
            }
        }

        public string PublicationNumber
        {
            get
            {
                return this._PublicationNumber;
            }
        }

        public string Remarks
        {
            get
            {
                return this._Remarks;
            }
        }

        public string Status
        {
            get
            {
                return this._Status;
            }
        }

        public string Title
        {
            get
            {
                return this._Title;
            }
        }

        public string Type
        {
            get
            {
                return this._Type;
            }
        }
    }
}

